from copy import deepcopy
from api_py.entity.request import Request
from api_py.test.api_request import get_cookies
from api_py.test.settings import base_url, base_headers
from api_py.utils.MD5 import MD5Encode
from api_py.utils.parse_data import format_body, format_params


# 接口1
def api01_auth_login(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    for request_case in requests:
        # 创建一个请求
        request = Request(url, deepcopy(base_headers), {}, format_body(request_case["body"]))

        # 设置请求体信息
        request.body['password'] = MD5Encode(request.body['password'])

        request_arr.append(request)

    return request_arr

# 接口2
def api02_logout(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies() # 得到cookie列表

    for request_case in requests:
        # 创建一个请求
        request = Request(url, deepcopy(base_headers), {}, {})

        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]

        request_arr.append(request)

    return request_arr

# 接口4
def api04_auth_me(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求
        request = Request(url, deepcopy(base_headers), {}, {})

        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]

        request_arr.append(request)

    return request_arr

# 接口5
def api05_user_ms(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求
        request = Request(url, deepcopy(base_headers), {}, format_body(request_case["body"]))

        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]
        request.body['password'] = MD5Encode(request.body['password'])

        request_arr.append(request)

    return request_arr

# 接口6
def api06_user_list(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求
        request = Request(url, deepcopy(base_headers), format_params(request_case["params"]), {})

        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]  # 配置对应的Cookie

        request_arr.append(request)

    return request_arr

# 接口8
def api08_user_ms_supervisor(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求
        request = Request(url, deepcopy(base_headers), {}, format_body(request_case["body"]))

        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]  # 配置对应的Cookie

        request_arr.append(request)

    return request_arr

# 接口9
def api09_user_ms_counselor(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求
        request = Request(url, deepcopy(base_headers), {}, format_body(request_case["body"]))

        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]  # 配置对应的Cookie

        request_arr.append(request)

    return request_arr

# 接口10
def api10_1_user_ms_supervisor_list(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求
        request = Request(url, deepcopy(base_headers), format_params(request_case["params"]), {})

        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]  # 配置对应的Cookie

        request_arr.append(request)

    return request_arr

# 接口10.2
def api10_2_user_ms_counselor_list(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求
        request = Request(url, deepcopy(base_headers), format_params(request_case["params"]), {})

        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]  # 配置对应的Cookie

        request_arr.append(request)

    return request_arr


# 接口 11
def api11_user_ms_supervisor(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求
        request = Request(url, deepcopy(base_headers), {}, format_body(request_case["body"]))
        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]  # 配置对应的Cookie
        request.body['password'] = MD5Encode(request.body['password'])

        request_arr.append(request)

    return request_arr

# 接口 12
def api12_user_ms_counselor(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求
        request = Request(url, deepcopy(base_headers), {}, format_body(request_case["body"]))
        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]  # 配置对应的Cookie

        request_arr.append(request)

    return request_arr

def api13_user_ms_supervisor(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求
        request = Request(url, deepcopy(base_headers), {}, {})

        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]  # 配置对应的Cookie
        # 设置url参数
        request.url = request.url.format(username=request_case["params"]["username"]["value"])  # 将id写入url

        request_arr.append(request)

    return request_arr

def api14_user_ms_counselor(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求
        request = Request(url, deepcopy(base_headers), {}, {})

        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]  # 配置对应的Cookie
        # 设置url参数
        request.url = request.url.format(username=request_case["params"]["username"]["value"])  # 将id写入url

        request_arr.append(request)

    return request_arr

# 接口15
def api15_user_ban(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求
        request = Request(url, deepcopy(base_headers), {}, {})

        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]  # 配置对应的Cookie
        # 设置url参数
        request.url = request.url.format(userId=request_case["params"]['userId']["value"]) # 将id写入url

        request_arr.append(request)

    return request_arr

# 接口16
def api16_user_list(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求
        request = Request(url, deepcopy(base_headers), format_params(request_case["params"]), {})
        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]  # 配置对应的Cookie

        request_arr.append(request)

    return request_arr

# 接口17
def api17_user_password(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求
        request = Request(url, deepcopy(base_headers), {}, format_body(request_case["body"]))
        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]  # 配置对应的Cookie
        request.body['oldPassword'] = MD5Encode(request.body['oldPassword'])
        request.body['password'] = MD5Encode(request.body['password'])

        request_arr.append(request)

    return request_arr

# 接口18
def api18_user_update(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求
        request = Request(url, deepcopy(base_headers), {}, format_body(request_case["body"]))
        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]  # 配置对应的Cookie

        request_arr.append(request)

    return request_arr

# 接口20
def api20_user_active(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求
        request = Request(url, deepcopy(base_headers), {}, {})

        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]  # 配置对应的Cookie
        # 设置url参数
        request.url = request.url.format(id=request_case["params"]['userId']["value"])  # 将id写入url

        request_arr.append(request)

    return request_arr

# 接口21
def api21_user_maxconsults(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求，并设置请求体参数
        request = Request(url, deepcopy(base_headers), {}, format_body(request_case["body"]))

        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]  # 配置对应的Cookie

        request_arr.append(request)

    return request_arr

def api22_arrange(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求，并设置请求体参数
        request = Request(url, deepcopy(base_headers), {}, format_body(request_case["body"]))

        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]  # 配置对应的Cookie

        request_arr.append(request)

    return request_arr

# 接口23
def api23_arrange_batch(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求，并设置请求体参数
        request = Request(url, deepcopy(base_headers), {}, format_body(request_case["body"]))

        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]  # 配置对应的Cookie

        request_arr.append(request)

    return request_arr

# 接口24
def api24_arrange_theday(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求，并设置请求体参数
        request = Request(url, deepcopy(base_headers), format_params(request_case["params"]), {})

        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]  # 配置对应的Cookie

        request_arr.append(request)

    return request_arr

# 接口25
def api25_arrange(requests, api_type):
    url = base_url + api_type.value[0]["url"]
    request_arr = []
    cookies = get_cookies()  # 得到cookie列表

    for request_case in requests:
        # 创建一个请求，并设置请求体参数
        request = Request(url, deepcopy(base_headers), {}, {})

        # 设置请求头cookie
        request.headers["Cookie"] = cookies[request_case["headers"]["Cookie"]["value"]]  # 配置对应的Cookie
        # 设置url参数
        request.url = request.url.format(id=request_case["params"]['id']["value"])  # 将id写入url

        request_arr.append(request)

    return request_arr